package com.webkit.web;

import com.lamfire.logger.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ApplicationConfiguretion {
	static final Logger LOGGER = Logger.getLogger(ApplicationConfiguretion.class);
	public static final String CONF_FILE = "application.properties";
	public static final String ACTION_ROOT = "action.class.root";
	public static final String MULTIPART_TEMPDIR = "request.multipart.tempdir";
	public static final String MULTIPART_LIMIT = "request.multipart.limit";
	private static ApplicationConfiguretion conf;
	private static final Properties prop = new Properties();

	private ApplicationConfiguretion(InputStream in) {
		try {
			prop.load(in);
			LOGGER.info("found property - " + prop);
		} catch (IOException e) {
			LOGGER.error("Application can not load file application.properties", e);
			throw new RuntimeException(e.getMessage());
		}
	}

	public String get(String key) {
		return prop.getProperty(key);
	}

	public String getProperty(String key) {
		return conf.get(key);
	}

	public String getActionRootPath() {
		return conf.get("action.class.root");
	}

	public String getMultipartTempDir() {
		return conf.get("request.multipart.tempdir");
	}

	public long getMultipartSizeLimit() {
		long limit = 10000000L;
		String value = conf.get("request.multipart.limit");
		try {
			limit = Long.parseLong(value);
		} catch (Exception localException) {
		}
		return limit;
	}

	public static ApplicationConfiguretion getInstance(InputStream input) {
		if (conf == null) {
			conf = new ApplicationConfiguretion(input);
		}
		return conf;
	}
}